package com.cincc.cinccimdemo.viewholder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.adapter.ConversationAdapter;
import com.cincc.cinccimdemo.model.MessageInfoUI;
import com.cincc.im.model.enums.SendStatus;
import com.cincc.im.model.message.ImAudioMessage;
import com.cincc.im.model.message.ImVideoMessage;

public class SendAudioHolder extends MessageContentHolder {
    public ImageView iv_face;
    public ImageView iv_message;
    public TextView tv_duration;
    public RelativeLayout rl_message;
    public TextView tv_time;
    public ImageView iv_error;
    public ProgressBar pb_loading;

    public SendAudioHolder(Context context, View itemView, ConversationAdapter adapter) {
        super(context, itemView, adapter);
        iv_face = itemView.findViewById(R.id.iv_face);
        iv_message = itemView.findViewById(R.id.iv_message);
        tv_duration = itemView.findViewById(R.id.tv_duration);
        rl_message = itemView.findViewById(R.id.rl_message);
        tv_time = itemView.findViewById(R.id.tv_time);
        iv_error = itemView.findViewById(R.id.send_error_image);
        pb_loading = itemView.findViewById(R.id.progress);
    }

    @Override
    public void bindView(MessageInfoUI uiMessage, int position) {
        super.bindView(uiMessage, position);
        ImAudioMessage imAudioMessage = (ImAudioMessage) uiMessage.getMessageInfo().imMessage;

        tv_duration.setText(imAudioMessage.duration + "\"");
        setAudioWidth(imAudioMessage.duration, rl_message, context);
        setAudioDrawable(uiMessage, iv_message, true);
        rl_message.setOnClickListener(v -> {
            conversationViewModel.playAudioMessage(uiMessage);
        });
        iv_error.setVisibility(uiMessage.getMessageStatus() == SendStatus.SEND_FAILED ? View.VISIBLE : View.GONE);
        pb_loading.setVisibility(uiMessage.getMessageStatus() == SendStatus.SEND_ING ? View.VISIBLE : View.GONE);
    }

}
